package com.aaa.pro.dao;

import feign.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Classname ProAppraise
 * @Description TODO
 * @Date 2020/1/12 15:52
 * @Created by admin
 * @author:GT
 * @version:1.0.0
 */
public interface ProAppraiseDao {

    /**
     * 商品评价表
     * @return
     */
    @Select("select member_ip,star,content,product_attribute,date_format(create_time, '%Y-%m-%d %H:%i:%s') as create_time from pms_comment")
    List<Map> getProAppraise();

    /**
     * 获取首页评价的信息内容
     * @return
     */
    @Select("select star,member_nick_name,pics,content,member_icon,DATE_FORMAT(p.create_time,'%Y-%m-%d %H:%m:%s') comment_time,order_status from pms_comment p left join oms_order o on p.order_id=o.id where p.shop_id = 1 limit 2")
    List<Map> getHomeComment();

    /**
     * 获取所以评价的总数
     * @return
     */
    @Select("select count(*) evaluationNumber,round(avg(star),1) avgScore from pms_comment")
    List<Map> getCommentData();

    /**
     * 全部的商品评价
     * （测试）
     */
    @Select("select p.id,star,member_nick_name,pics,content,member_icon,DATE_FORMAT(p.create_time,'%Y-%m-%d %H:%m:%s') comment_time,order_status from pms_comment p left join oms_order o on p.order_id=o.id where p.shop_id = 1  order by p.id limit #{sequenceNum},5")
    List<Map> getAllevaluation(int sequenceNum);

    /**
     * 添加评论
     * @return
     */
    @Insert("INSERT into pms_comment VALUES(null,1,null,null,#{member_nick_name},null,#{star},null,CURRENT_TIMESTAMP,null,null,null,null,#{content},#{pics},#{member_icon},null)")
    int AddComment(Map map);

}
